﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using facebook.Schema;
using IFrameSample.util;
using IFrameSample.controls;
using IFrameSample.util;
using System.Web.Configuration;

namespace IFrameSample
{
    public partial class Home : System.Web.UI.Page
    {
        protected void Page_PreInit(object sender, EventArgs e)
        {

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var pref = this.Master.API.data.getUserPreference(1);
            if (pref != "set")
            {
                this.Master.API.profile.setInfo("My Smiles", 5, getSampleInfo(), this.Master.API.uid);
                this.Master.API.profile.setFBML(this.Master.API.uid, null, getUserProfileBox(), null); 
            }
            hello.Text = "Hello " + this.Master.API.uid;

        }

        private List<info_item> getSampleInfo()
        {
            var callback = WebConfigurationManager.AppSettings["Callback"];
            var suffix = WebConfigurationManager.AppSettings["Suffix"];
            var options = new List<info_item>();
            options.Add(new info_item { label = "Happy", image = callback + "images/smile0.jpg", sublabel = "", description = "The original and still undefeated.", link = "http://apps.facebook.com/" + suffix + "/smile.aspx?smile=1" });
            options.Add(new info_item { label = "Indifferent", image = callback + "images/smile1.jpg", sublabel = "", description = "meh....", link = "http://apps.facebook.com/" + suffix + "/smile.aspx?smile=2" });
            options.Add(new info_item { label = "Sad", image = callback + "images/smile2.jpg", sublabel = "", description = "Oh my god! you killed my dog!", link = "http://apps.facebook.com/" + suffix + "/smile.aspx?smile=3" });
            options.Add(new info_item { label = "Cool", image = callback + "images/smile3.jpg", sublabel = "", description = "Yeah. whatever", link = "http://apps.facebook.com/" + suffix + "/smile.aspx?smile=4" });
            return options;
        }

        private string getUserProfileBox()
        {
            return Utilities.RenderFBML(typeof(ProfileBox));
        }
    }
}
